<%--
  Created by IntelliJ IDEA.
  User: DELL
  Date: 2020/11/21
  Time: 16:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="layui/css/layui.css">
    <link rel="stylesheet" href="layui/css/login.css">
    <title>找回密码</title>
</head>
<body>
<div class="login-main">
<header class="layui-elip">找回密码</header>
<form class="layui-form" action="reset_pwd" method="post" onsubmit="return check()">
    <div class="layui-input-inline">
        <label>
            <input type="text" id="user" name="name" required placeholder="用户名" class="layui-input">
        </label>
    </div>
    <div class="layui-input-inline">
        <select name="question" id="question"  lay-verify="required">
            <option value="">请选择你设置的密保问题</option>
            <option value="出生年月">你的出生年月？</option>
            <option value="小学地点">你的小学地点？</option>
            <option value="手机号码">你的手机号码？</option>
            <option value="你父亲的名字">你父亲的名字？</option>
            <option value="你母亲的名字">你母亲的名字？</option>
        </select>
    </div>
    <div class="layui-input-inline">
        <label>
            <input type="text" name="answer" id="answer" required  placeholder="请输入密保答案" class="layui-input">
        </label>
    </div>
    <div class="layui-input-inline">
        <label>
            <input type="password" id="pwd" name="password" required  placeholder="输入新密码" class="layui-input">
        </label>
    </div>
    <div class="layui-input-inline">
        <label>
            <input type="password" name="password" id="repwd" required  placeholder="确认新密码" class="layui-input">
        </label>
    </div>
    <div class="layui-input-inline login-btn">
        <button class="layui-btn" onclick="checkform()">确认</button>
    </div>
</form>
</div>
<script src="layui/layui.all.js"></script>
<script>
    function check(){
        var $user_name = document.getElementById("user").value;
        var $user_pwd = document.getElementById("pwd").value;
        var $user_repwd = document.getElementById("repwd").value;
        var $question = document.getElementById("question").value;
        var $answer = document.getElementById("answer").value;
        var $flag=false;
        const $=layui.$;
        if($user_pwd!=$user_repwd) {
            layer.msg("两次密码不一致");
            return $flag;
        }
        $.ajax({
            url: '/Test1_war/user/reset/',
            type: 'POST',
            data: {username: $user_name,
                password:$user_pwd,
                question:$question,
                answer:$answer},
            async: false,
            success: function (res) {
                if (res.code === 200) {
                    alert('修改成功');
                    $flag=true;
                } else {
                    layer.msg('验证失败');
                }
            }
            , error(error) {
                layer.close(index)
                layer.msg('http请求错误')
            }
        });
        return $flag;
    }
</script>
</body>
</html>
